<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body style="text-align: center">
<div>
    <div>
        <label for="fromUserId">userName</label>
        <input type="text" name="fromUserId" id="fromUserId" required placeholder="fromUserId">
    </div>
    <div>
        <label for="content">content</label>
        <input type="text" name="content" id="content" required placeholder="content">
    </div>
    <div>
        <label for="toUserId">toUserId</label>
        <input type="text" name="toUserId" id="toUserId" required placeholder="toUserId">
    </div>
    <div>
        <input type="button" value="submit" id="sub">
    </div>
</div>
</body>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#sub").on('click', function () {
            var fromUserId = $("#fromUserId").val();
            var content = $("#content").val();
            var toUserId = $("#toUserId").val();

            var subData = {"fromUserId": fromUserId, "content": content, "toUserId": toUserId};

            /*$.post("/submsg.do", JSON.stringify(subData), function (data,status,xhr) {
                if (data.result){
                    alert("success");
                }
            },"json")*/

            $.ajax({
                url: "/submsg.do",
                dataType: "json",
                async: false,
                type: "POST",
                data: JSON.stringify(subData),
                contentType: "application/json",
                success: function (data, status, xhr) {
                    if (data.result) {
                        alert("success");
                    }
                },
                error: function (a,b,c) {
                    console.log(a);
                    console.log(b);
                    console.log(c);
                }

            })
        })
    })
</script>
</html>